<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/assets/plugins/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<head th:include="include::ztree-css"></head>

<body class="white-bg">
	<div class="ui-layout-west">
		<div class="main-content">
			<div class="box box-main">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-grid"></i> 组织机构
					</div>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
					</div>
				</div>
				<div class="ui-layout-content">
					<div id="tree" class="ztree" style="width:240px; overflow:auto;"></div>
				</div>
			</div>
		</div>
	</div>
<div class="container-div ui-layout-center">	
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-exarrange-add">
		<input id="ksid" name="ksid" th:value="${ksid}" type="hidden">
		<input id="role" name="role" type="hidden">
	<div class="form-group">
				<label class="col-sm-3 control-label">指定某些类型的用户为考生（可选）：</label>
				<div class="col-sm-8">
					<label th:each="role:${roles}" class="check-box">
						<input name="roles" type="checkbox" th:value="${role.id}" th:text="${role.roleName}" th:disabled="${role.status == '1'}">
					</label>
				</div>
			</div>
	<div class="form-group">
			<label class="col-sm-3 control-label">指定考生（部门编号、用户登录名或班级）：</label>
			<div class="col-sm-8">
			<a class="btn btn-danger" onclick="adddept()"> 添加整个部门的用户为考生 </a>
				<input id="ksuser" name="ksuser" class="form-control" type="text">
			</div>
		</div>
			<div class="form-group">
			<label class="col-sm-3 control-label">批次：</label>
			<div class="col-sm-8">
				<input id="pc" name="pc" class="form-control" type="text">
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">考场号：</label>
			<div class="col-sm-8">
				<input id="kch" name="kch" class="form-control" type="text">
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">指定IP：</label>
			<div class="col-sm-8">
				<input id="loginip" name="loginip" class="form-control" type="text">
			</div>
		</div>
	
		<div class="form-group">
			<label class="col-sm-3 control-label">开始时间：</label>
			<div class="col-sm-8 input-group date">
				<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				<input id="starttime" name="starttime"  class="form-control" type="text">
			</div>
		</div>
				<div class="form-group">
			<label class="col-sm-3 control-label">结束时间：</label>
			<div class="col-sm-8 input-group date">
				<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				<input id="endtime" name="endtime" class="form-control" type="text">
			</div>
		</div>
	<div class="form-group">
			<div class="col-sm-8 input-group date">
				<a class="btn btn-success" onclick="submitHandler()" shiro:hasPermission="exam:exarrange:add">
					<i class="fa fa-plus"></i> 为选择的用户抽题组卷
				</a>
			</div>
		</div>
	</form>
</div>
</div>
<div th:include="include::footer"></div>
	<script th:src="@{/assets/plugins/jquery-layout/jquery.layout-latest.js}"></script>
<div th:include="include::ztree-js"></div>

<script type="text/javascript">
	var prefix = ctx + "exam/exarrange"
	var deptId="",parentId="";
	$("#form-exarrange-add").validate({
		onkeyup: false,
		rules:{
			pc:{
				digits:true,
			},
		}
	});

	function submitHandler() {
		if ($.validate.form()) {
			var roleIds = $.form.selectCheckeds("roles");
			if($("#ksuser").val().length==0 &&roleIds && roleIds.length==0){
				$.modal.alertWarning("没有指定考生");
				return;
			}
			$("#role").val(roleIds);
			$.operate.save(prefix + "/addDo", $('#form-exarrange-add').serialize());
		}
	}
	function now(){
		return $.format.date(new Date(),"yyyy-MM-dd HH:mm");
	}
	$(function(){
		layui.use('laydate', function(){
     		  var laydate = layui.laydate;
     		 var startDate = laydate.render({ 
        		    elem: '#starttime',
        		    type: 'datetime',
    		        theme: 'molv',
    		        trigger: 'click',
    		        value: new Date("[[${#dates.format(paperdef.starttime,'yyyy-MM-dd HH:mm:ss')}]]"),//初始值
    		        done: function(value, date) {
    		            // 结束时间大于开始时间
    		            if (value !== '') {
    		                endDate.config.min.year = date.year;
    		                endDate.config.min.month = date.month - 1;
    		                endDate.config.min.date = date.date;
    		                endDate.config.min.hours = date.hours;
    		                endDate.config.min.minutes = date.minutes+1;
    		                endDate.config.min.seconds = date.seconds;
    		                //$("#title").val($.format.date(new Date(value),"yyyy-MM-dd HH:mm")+$("#title").val());
    		            } else {
    		                endDate.config.min.year = '';
    		                endDate.config.min.month = '';
    		                endDate.config.min.date = '';
    		                endDate.config.min.hours = '';
    		                endDate.config.min.minutes = '';
    		                endDate.config.min.seconds = '';
    		            }
    		        }
        		  });
     		var endDate = laydate.render({ 
    		    elem: '#endtime',
    		    type: 'datetime',
    		    min: $('#starttime').val(),
		        theme: 'molv',
		        trigger: 'click',
		        value: new Date("[[${#dates.format(paperdef.endtime,'yyyy-MM-dd HH:mm:ss')}]]"),
		        done: function(value, date) {
		            // 开始时间小于结束时间
		            if (value !== '') {
		                startDate.config.max.year = date.year;
		                startDate.config.max.month = date.month - 1;
		                startDate.config.max.date = date.date;
		                startDate.config.min.hours = date.hours;
		                startDate.config.min.minutes = date.minutes-1;
		                startDate.config.min.seconds = date.seconds;
		            } else {
		                startDate.config.max.year = '';
		                startDate.config.max.month = '';
		                startDate.config.max.date = '';
		                startDate.config.min.hours = '';
		                startDate.config.min.minutes = '';
		                startDate.config.min.seconds = '';
		            }
		        }
    		  });
		});
	});
	$(function() {
	    var panehHidden = false;
	    if ($(this).width() < 769) {
	        panehHidden = true;
	    }
	    $('body').layout({ initClosed: panehHidden, west__size: 235 });
	    queryDeptTree();
	});
	function queryDeptTree()
	{
		var url = ctx + "sys/dept/treeData";
		var options = {
	        url: url,
	        expandLevel: 2,
	        onClick : zOnClick
	    };
		$.tree.init(options);
		
		function zOnClick(event, treeId, treeNode) {
			deptId=treeNode.id;
			parentId=treeNode.pId;
		}
	}
	function adddept(){
		var ksuser=$("#ksuser").val();
		$("#ksuser").val(ksuser+(ksuser.length>0?",":"")+deptId);
	}
	$('#btnExpand').click(function() {
		$._tree.expandAll(true);
	    $(this).hide();
	    $('#btnCollapse').show();
	});
	
	$('#btnCollapse').click(function() {
		$._tree.expandAll(false);
	    $(this).hide();
	    $('#btnExpand').show();
	});
	
	$('#btnRefresh').click(function() {
		queryDeptTree();
	});

</script>
</body>
</html>
